package com.zhhh.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class BootstrapUiTreeNode implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String id;
	private String title;
	private String ico;
	private String link;
	private String model;
	private String width;
	private String height;
	private String hasChilds;
	// 子叶节点
	private List<BootstrapUiTreeNode> childs = new ArrayList<>();
	// 统计该节点分类下文档的数量
	private List<String> tags = new ArrayList<>(); // tags: ['NUM']

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getIco() {
		return ico;
	}

	public void setIco(String ico) {
		this.ico = ico;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getHasChilds() {
		return hasChilds;
	}

	public void setHasChilds(String hasChilds) {
		this.hasChilds = hasChilds;
	}

	public List<BootstrapUiTreeNode> getChilds() {
		return childs;
	}

	public void setChilds(List<BootstrapUiTreeNode> childs) {
		this.childs = childs;
	}

	public List<String> getTags() {
		return tags;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public static List<BOrganization> getRootNodeList(List<BOrganization> listOr) {
		List<BOrganization> rootNodeList = new ArrayList<BOrganization>();
		for (BOrganization organization : listOr) {
			if (organization.getPid() == 0) {
				BootstrapUiTreeNode node = new BootstrapUiTreeNode();
				node.setId(organization.getId() + "");
				node.setTitle(organization.getOname());
				rootNodeList.add(organization);
			}
		}
		return rootNodeList;
	}

	/**
	 * 	使用递归构建组织结构Json对象
	 * @param listOr
	 * @param parentNode
	 * @return
	 */
	public static BOrganization getChildNodeList(List<BOrganization> listOr, BOrganization parentNode) {
		List<BOrganization> rootNodeList = new ArrayList<BOrganization>();
		for (int i = 0; i < listOr.size(); i++) {
			if (listOr.get(i).getPid() == parentNode.getId()) {
				rootNodeList.add(listOr.get(i));
			}
		}
		parentNode.setChildList(rootNodeList);
		if(rootNodeList.size()>0) {
			for (int i = 0; i < rootNodeList.size(); i++) {
				getChildNodeList(listOr,rootNodeList.get(i));
			}
		}
		return parentNode;
	}
	
	/**
	 * 	使用递归构建组织结构Json对象
	 * @param listOr
	 * @param parentNode
	 * @return
	 */
	public static BootstrapUiTreeNode getChildNodeList2(List<BOrganization> listOr, BootstrapUiTreeNode parentNode) {
		List<BootstrapUiTreeNode> treeRootNodeList = new ArrayList<BootstrapUiTreeNode>();
		for (int i = 0; i < listOr.size(); i++) {
			if (listOr.get(i).getPid() == Integer.parseInt(parentNode.getId()) ) {
				BootstrapUiTreeNode treeNode = new BootstrapUiTreeNode();
				treeNode.setId(listOr.get(i).getId().toString());
				treeNode.setTitle(listOr.get(i).getOname());
				treeRootNodeList.add(treeNode);
			}
		}
		parentNode.setChilds(treeRootNodeList);
		parentNode.setModel("0");
		parentNode.setLink("./organization_edit.html");
		if(treeRootNodeList.size()>0) {//还有子节点继续调用自己
			for (int i = 0; i < treeRootNodeList.size(); i++) {
				getChildNodeList2(listOr,treeRootNodeList.get(i));
			}
		}else{//没有子节点
			//parentNode.setLink("./organization_edit.html");
		}
		return parentNode;
	}
	
	
	public static List<BootstrapUiTreeNode> getRootNodeList2(List<BOrganization> listOr) {
		List<BootstrapUiTreeNode> rootNodeList = new ArrayList<BootstrapUiTreeNode>();
		for (BOrganization organization : listOr) {
			if (organization.getPid() == 0) {
				BootstrapUiTreeNode node = new BootstrapUiTreeNode();
				node.setId(organization.getId() + "");
				node.setTitle(organization.getOname());
				rootNodeList.add(node);
			}
		}
		return rootNodeList;
	}

}
